<template>
	<view :class="currentTheme">
		<a-nabbar :name="isAll ? '门店录入' :'提交意向'" />
		<view v-if="list.length" class="u-padding-32">
			<item-box padding="0">
				<view class="group-box">
					<u-checkbox-group wrap shape="circle">
						<u-checkbox v-for="(item, index) in list" :key="index" active-color="#765CFE" v-model="item.checked"
							:name="item.id">
							<text class="content-desc-item u-font-32">{{item.name}}</text>
						</u-checkbox>
					</u-checkbox-group>
				</view>
			</item-box>
		</view>
		<empty v-else />
		<fixed-team :btnText="!isAll ? '提交':'录入'"  v-if="list.length" @btnClick="change"></fixed-team>
	</view>
</template>

<script>
	import {
		getDetail,
		add
	} from '@/api/crud.js'
	import empty from '@/components/mescroll-uni/components/mescroll-empty.vue'
	export default {
		data() {
			return {
				exhibitId: '',
				apiModule: 'shopApi',
				apiType: "systemStore",
				list: [],
				option: {}
			};
		},
		components: {
			empty
		},
		computed: {
			isAll() {
				return this.option.type !== 'findByExhibitUser';//isall 如果不是意向选择门店 就是参展信息门店录入
			}
		},
		onLoad(option) {
			this.option = option
			this.getDetail()
		},
		methods: {
			getDetail() {
				getDetail({
					uid: this.loginForm.uid
				}, this.apiType, this.apiModule, this.option.type || 'all').then(res => {
					const storeIdList = this.option.storeIds ? this.option.storeIds.split(',') : [];
					this.list = res.map(val => {
						val.checked = !this.isAll ? false : storeIdList.some(item => item == val.id)
						return val;
					})
				});
			},
			change() {
				//11.30日 尹哥说取消前端限制 通过后端限制
				// if(this.isAll){
				// 	const notDz = this.list.find(val=>!val.dzUid) || '';
				// 	if(notDz){
				// 		this.$u.toast(`${notDz.name}需要指定店长才能录入`)
				// 		return false;
				// 	}
				// }
				const storeIds = this.list.filter(val => val.checked).map(val => val.id).join(',');
				uni.$emit('setStoreIds', storeIds)
				this.$u.route({
					type: "back"
				})
			}
		},
	}
</script>

<style lang="scss">
	page{
		.group-box{
			/deep/.u-checkbox{
				display: flex;
				align-items:flex-start;
				padding-top: 66rpx;
				&-group{
					display: flex;
					flex-direction: column;
				}
				.u-checkbox__icon-wrap{
					margin-top: 10rpx;
				}
				.u-checkbox__label{
					flex: 1;
					padding: 0 20rpx 66rpx 0;
					margin-right: 0;
					margin-left: 30rpx;
					border-bottom: 1rpx solid rgba($color: #000000, $alpha: 0.1);
				}
			}
		}
	}
</style>
<style lang="scss" scoped>
.group-box{
	padding-left: 47rpx;
}
</style>
